package net.bwie.realtime.dws.log.function;

import net.bwie.realtime.dws.log.bean.PageViewBean;
import org.apache.flink.api.common.functions.ReduceFunction;

public class PageViewReportReduceFunction implements ReduceFunction<PageViewBean> {

    @Override
    public PageViewBean reduce(PageViewBean value1, PageViewBean value2) throws Exception {
        // value1：表示增加计算中间结果；value2：表示窗口中每条数据
        // 1.增量计算：表示各个指标相加
        value1.setPvCount(value1.getPvCount() + value2.getPvCount());
        value1.setPvDuringTime(value1.getPvDuringTime() + value2.getPvDuringTime());
        value1.setUvCount(value1.getUvCount() + value2.getUvCount());
        value1.setSessionCount(value1.getSessionCount() + value2.getSessionCount());
        // 2.返回结果
        return value1;
    }
}
